<%@ page import="java.sql.Connection" %>
<%@ page import="java.sql.DriverManager" %>
<%@ page import="java.sql.Statement" %>
<%@ page import="java.sql.ResultSet" %><%--
  Created by IntelliJ IDEA.
  User: hua'wei
  Date: 2023/5/19
  Time: 15:34
  To change this template use File | Settings | File Templates.
--%>
<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<html>
<head>
  <title>Title</title>
  <script>
    function decrease() {
      var quantity = document.getElementById("quantity");
      var value = parseInt(quantity.value);
      if (value > 1) {
        quantity.value = value - 1;
      }
    }

    function increase() {
      var quantity = document.getElementById("quantity");
      var value = parseInt(quantity.value);
      quantity.value = value + 1;
    }

  </script>
</head>
<body>
<div style="text-align: center">
  <div>
    <h1>购物车</h1>
    <br>
    <br>
    <br>
    <br>

  </div>
  <div style="text-align: center;position: center ;margin: auto">
    <br>
    <br>
    <table width="800" border="1" cellpadding="0" align="center">
      <tr>
        <th>序号</th>
        <th>商品名称</th>
        <th>单价</th>
        <th>数量</th>
        <th>总额</th>
        <th>操作</th>
      </tr>
      <%
        String shop = request.getParameter("shop");
        String driverClass = "com.mysql.jdbc.Driver";
        String url = "jdbc:mysql://localhost:3306/cart?serverTimezone=Asia/Shanghai";
        String user = "root";
        String password = "111111";
        Connection conn;
        try {
          Class.forName(driverClass);
          conn = DriverManager.getConnection(url, user, password);
          Statement stmt = conn.createStatement();
          String sql = "select * from shop where shop='" + shop + "'";
          ResultSet rs = stmt.executeQuery(sql);
          while (rs.next()) {
      %>
      <%--            DetailServlet?shop=${Cake.shop}   --%>
      <tr align="center">
        <td><%=rs.getString("id")%>
        </td>
        <td><%=rs.getString("shop")%>
        </td>
        <td><%=rs.getString("price")%>
        </td>
        <td>
          <button onclick="decrease()">-</button>
          <input type="text" id="quantity" name="quantity" value="1">
          <button onclick="increase()">+</button>
        <td>
        <td>
          <a href="cart.jsp">返回</a>
          <a href="cart.jsp">删除</a>
        </td>
      </tr>
      <%
        String num = rs.getString("num");
        String price = rs.getString("price");
        double total = 0;
      %>
      <%--            <%=rs.getDouble("total")%>--%>
      <div>
        <a>总金额：<%=total%>
        </a>
      </div>
      <%
          }
        } catch (Exception ex) {
          ex.printStackTrace();
        }
      %>
    </table>
  </div>
</div>
</body>
</html>
